package com.gooznt.wrapperProp;

public abstract class Wrapper<O extends IWrapperOutput> {

	private PageGetter pageGetter;
	private WrapperReader reader;
	private WrapperCsvWriter writer;
	
	public Wrapper(String urlFile, String csvOutputFile){
		this.reader = new WrapperReader(urlFile);
		this.writer = new WrapperCsvWriter(csvOutputFile);
	}
	
	/**
	 * Main thread of the wrapper, get each url from the url file, and put the corresponding output
	 * to the csv file.
	 */
	public void getAllResults(){
		String s;
		while ((s = reader.getNextLine())!=null){
			String html = pageGetter.getHtml(s);
			DataExtractor<O> extractor = getExtractor();
			O output = extractor.getOutputFromHtml(html);
			writer.writeInFile(output);
		}
		writer.closeFile();
	}

	public abstract DataExtractor<O> getExtractor();
	
}
